package org.king.controller;

import org.springframework.stereotype.Component;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;

public class DetailController {
    @FXML
    private TextField txtActivityId;
    @FXML
    private Button btnSearch;
    @FXML
    private Button btnCancel;

    private MainController mainController;

    public void setMainController(MainController mainController) {
        this.mainController = mainController;
    }

    @FXML
    private void initialize() {
        btnSearch.setOnAction(event -> {
            try {
                int activityId = Integer.parseInt(txtActivityId.getText());
                mainController.showActivityDetailsById(activityId);
                ((javafx.stage.Stage) btnSearch.getScene().getWindow()).close();
            } catch (NumberFormatException e) {
                // 显示错误信息
                javafx.scene.control.Alert alert = new javafx.scene.control.Alert(
                        javafx.scene.control.Alert.AlertType.ERROR);
                alert.setTitle("错误");
                alert.setHeaderText("无效的活动ID");
                alert.setContentText("请输入有效的数字ID");
                alert.showAndWait();
            }
        });

        btnCancel.setOnAction(event -> {
            ((javafx.stage.Stage) btnCancel.getScene().getWindow()).close();
        });
    }
}